import asyncio
from functools import partial
from typing import Any, List
from app.embedding.com_mbeddings import ComEmbeddings
from langchain_community.vectorstores.milvus import Milvus
from langchain.schema import Document
from app.config.milvus import MilvusConfig, MilvusIndexParam, MilvusSearchParam

class MilvusVectorStore(Milvus):
    def __init__(self, collection_name,milvus_config: MilvusConfig=MilvusConfig().dict(),index_params=MilvusIndexParam().dict(),embedding=ComEmbeddings(),search_params=MilvusSearchParam().dict(),**kwargs):
        super().__init__(embedding_function=embedding,collection_name=collection_name,connection_args=milvus_config,index_params = index_params,search_params = search_params,drop_old=False,auto_id=True,consistency_level="Strong",**kwargs)

    async def adelete_by_expr(self, expr:str, partition_name=None):
        func=partial(self.delete, **{"expr":expr})
        return await asyncio.get_event_loop().run_in_executor(None, func)